package model.area;

import java.util.ArrayList;
import java.util.List;

import model.person.Person;

public class AreaManagement {
	private List<Area> areas = new ArrayList<Area>();
	private List<Reservation> reservations = new ArrayList<Reservation>();

	public AreaManagement() {
	}

	public String getAreaData() {
		GetAreaVisitor vis = new GetAreaVisitor();
		String data = "\nArea's in the system:";
		for (Area a : areas) {

			if (a instanceof Building) {
				data += vis.visit((Building) a);
			} else {
				data += vis.visit((Field) a);
			}
		}
		return data;
	}

	public void addField(String fieldName, int rent, boolean isArtificialGrass) {
		areas.add(new Field(fieldName, rent, isArtificialGrass));
	}

	public Field getField(String fieldName) {
		for (Area a : areas) {
			if (a.getName().equals(fieldName)) {
				return (Field) a;
			}
		}
		return null;
	}

	public void addBuilding(String buildingName, int rent, int serviceCosts) {
		areas.add(new Building(buildingName, rent, serviceCosts));
	}

	public void addReservation(String startDate, String stopDate,
			Person contactPerson, String[] areaStrings) {
		List<Area> reservationAreas = new ArrayList<Area>();
		for (String s : areaStrings) {
			for (Area a : areas) {
				if (a.getName().equals(s)) {
					reservationAreas.add(a);
				}
			}
		}
		reservations.add(new Reservation(startDate, stopDate, contactPerson,
				reservationAreas));

	}
}
